<template>
  <view>
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="swiper">
      
      <swiper-item v-for="(item,index) in swiperList" :key="item.goods_id">
        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?id='+item.goods_id">
        <image :src="item.image_src"></image>
        </navigator>
        </swiper-item>
    </swiper>
    <view class="cateList">
      <view class="cate-item" v-for="(item,index) in cateList" :key="index" @click="clicatehandle(item)">
        <image :src="item.image_src"></image>
      </view>
    </view>
    <view v-for="(item,index) in floorList" :key="index">
      <view>
        <image :src="item.floor_title.image_src" class="floorText"></image>
      </view>
      <view class="imgbox">
        <navigator class="imglft" :url="item.product_list[0].url">
           <image :src="item.product_list[0].image_src"
           :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image> 
        </navigator>
        <view class="imgright" >
         <navigator v-for="(item2,index2) in item.product_list" :key="index2" v-if="index2!==0" :url="item2.url">
          <image :src="item2.image_src"  :style="{width:item2.image_width+'rpx'}" mode="widthFix"></image>
         </navigator>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import badge from '../../mixin/tabbar-badge.js'
  export default {
    mixins:[badge],
    data() {
      return {
        swiperList:[],
        cateList:[],
        floorList:[]
      };
    },
  onLoad(){
   this.getSwiperList() 
   this.getCate()
   this.getfloorList()
  },
    methods:{
      //轮播图渲染
  async   getSwiperList() {
  const result=await  uni.$http.reqswiper()
  if(result.statusCode!==200){
   return uni.$showmsg()
  }
  this.swiperList=result.data.message
  
  },
  //首页分类渲染
async  getCate(){
 const result=   await uni.$http.reqcate()
 if(result.statusCode!==200) return uni.$showmsg()
this.cateList=result.data.message
console.log(result)
  },
  
  clicatehandle(item){
    if(item.name=='分类'){
      uni.switchTab({
        url:'../cate/cate'
      })
    }
  },
  //楼层渲染
async  getfloorList(){
 const result=  await uni.$http.reqfloorList() 
 if(result.statusCode!==200){
   return uni.$showmsg()
 }
 result.data.message.forEach(floor=>{
   floor.product_list.forEach(item=>{
     item.url='/subpkg/goods_list/goods_list?'+item.navigator_url.split('?')[1]
   })
 })
 this.floorList=result.data.message
 
  }
  
    }
  }
</script>

<style lang="scss">
.swiper{
  height: 330rpx;
  .swiper-item,
  image{
    width: 100%;
    height: 100%;
  }
}
.cateList{
  display: flex;
  justify-content: space-around;
  margin: 30rpx 0;
  image{
    width: 128rpx;
    height: 140rpx;
  }
}
.floorText{
  height: 60rpx;
}
.imgbox{
  display: flex;
  width: 100%;
  padding-left: 10rpx;
}
.imgright{
  display: flex;
 flex-wrap: wrap;
 justify-content:space-around;

}
</style>
